package com.yowasa.xiuxian.engine.battle.strategy.drop.all;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.google.common.collect.Lists;
import com.yowasa.xiuxian.annoations.BS;
import com.yowasa.xiuxian.constant.XiuxianConstants;
import com.yowasa.xiuxian.engine.battle.strategy.AttackStrategy;
import com.yowasa.xiuxian.engine.battle.strategy.BaseBattleStrategy;
import com.yowasa.xiuxian.engine.battle.strategy.CalAbility;
import com.yowasa.xiuxian.engine.battle.strategy.InherentStrategy;
import com.yowasa.xiuxian.entity.bo.battle.BattleContent;
import com.yowasa.xiuxian.entity.bo.battle.BuffContent;
import com.yowasa.xiuxian.entity.bo.battle.UserBattleContent;
import com.yowasa.xiuxian.entity.bo.user.UserBO;
import com.yowasa.xiuxian.entity.enums.ElementEnum;
import com.yowasa.xiuxian.entity.enums.InherentTiming;
import com.yowasa.xiuxian.exception.HandlerException;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.List;

@BS(name="奔狼庇护")
@Order(1)
@Component
public class BenLangBiHu extends CalAbility implements InherentStrategy {
    @Override
    public ElementEnum getElement() {
        return null;
    }
    @Override
    public void action(UserBattleContent first, UserBattleContent second, BattleContent content) {

        //血量的 5 % * 回复倍率
        int spell = (first.getBattleInfo().getHp()/20)*first.getBattleInfo().getRestoreRate()/100;
        //当前损失血量
        int needHp = first.getBattleInfo().getHp() - first.getBattleInfo().getChp();

        int can = Math.min(needHp, spell);

        first.getBattleInfo().setChp(first.getBattleInfo().getChp() + can);
        first.getBattleInfo().setCmp(first.getBattleInfo().getCmp() - 50);

        BuffContent buffContent = new BuffContent();
        buffContent.setDuration(2);
        buffContent.setNum(1);
        first.getBuff().put("狼灵庇佑", buffContent);
        content.getMsgLog().add(first.getUserBO().getName() + "因奔狼庇护回复" + can + "点血量,获得了强化");


    }

    @Override
    public void limit(UserBO user) {
        if (user.getStage() < 5) {
            throw new HandlerException("学习/使用奔狼庇护阶位需要在如曜之金以上");
        }
    }

    @Override
    public String limitDesc() {
        return "学习/使用奔狼庇护阶位需要在如曜之金以上";
    }

    @Override
    public boolean check(UserBattleContent user, BattleContent content) {
        if (user.getBattleInfo().getChp() >= user.getBattleInfo().getHp()) {
            return false;
        }
        if (user.getBattleInfo().getCmp() < 50) {
            return false;
        }
        return true;

    }

    @Override
    public String desc() {
        return "获得了北风王狼安德留斯的认可，孤高的灵魂将庇护你的前行\n自己行动开始时消耗50mp最高回复5%最大生命值的血量，并提升5%的物抗与法抗";
    }

    @Override
    public List<InherentTiming> getTiming() {
        return Lists.newArrayList(InherentTiming.SELF_BEGIN);
    }
}
